package com.huawei.appgallery.search.ui.card;

import android.content.Context;
import android.text.format.DateUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.search.ui.cardbean.SearchCampaignItemCardBean;
import huawei.widget.HwTextView;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import o.azb;
import o.cgz;
import o.cuv.a;
import o.cuv.b;
import o.cuv.f;
import o.cux;
import o.epv;
import o.eqx;

public class SearchCampaignItemCard extends BaseCompositeItemCard {
    private ImageView ʽ;
    private HwTextView ˋ;
    private View ᐝ;

    public SearchCampaignItemCard(Context context) {
        super(context);
    }

    public cgz ˏ(View view) {
        ˏ((ImageView) view.findViewById(b.ˊˋ));
        ॱ((TextView) (HwTextView) view.findViewById(b.ॱʽ));
        ˊ((TextView) (HwTextView) view.findViewById(b.ˌ));
        this.ˋ = (HwTextView) view.findViewById(b.ˊʼ);
        this.ʽ = (ImageView) view.findViewById(b.ˏˏ);
        this.ᐝ = view.findViewById(b.ʽ);
        ॱ(view.getContext(), this.ʽ);
        ʽ(view);
        return this;
    }

    public void w_() {
        eqx.ˏ(ʼॱ(), this.ˊᐝ.ॱˌ(), "image_default_icon");
    }

    public void ˏ(CardBean cardBean) {
        if (cardBean instanceof SearchCampaignItemCardBean) {
            super.ˏ(cardBean);
            SearchCampaignItemCardBean searchCampaignItemCardBean = (SearchCampaignItemCardBean) cardBean;
            ˏ(this.ʿ, searchCampaignItemCardBean.ॱ());
            ˏ(this.ˉ, searchCampaignItemCardBean.ˊ());
            long ॱ = ॱ(searchCampaignItemCardBean.ꜟ());
            long ॱ2 = ॱ(searchCampaignItemCardBean.ꜞ());
            long ॱ3 = ॱ(searchCampaignItemCardBean.ʽ());
            String ˎ;
            if (ॱ3 < ॱ) {
                ˎ = ˎ(ॱ);
                this.ˋ.setText(this.ʼॱ.getResources().getString(f.ॱॱ, new Object[]{ˎ}));
                ˎ(1.0f);
            } else if (ॱ3 < ॱ2) {
                ˎ = ˎ(ॱ2);
                this.ˋ.setText(this.ʼॱ.getResources().getString(f.ʼ, new Object[]{ˎ}));
                ˎ(1.0f);
            } else {
                this.ˋ.setText(this.ʼॱ.getResources().getString(f.ʻ));
                ˎ(0.3f);
            }
            if (ˎ()) {
                this.ʽ.setVisibility(8);
                if (searchCampaignItemCardBean.ॱㆍ()) {
                    this.ᐝ.setVisibility(8);
                    return;
                } else {
                    this.ᐝ.setVisibility(0);
                    return;
                }
            }
            this.ʽ.setVisibility(0);
            this.ᐝ.setVisibility(8);
        }
    }

    private long ॱ(String str) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        if (str == null) {
            return -1;
        }
        try {
            if (str.isEmpty()) {
                return -1;
            }
            return simpleDateFormat.parse(str).getTime();
        } catch (ParseException e) {
            cux.ˏ.ˊ("SearchCampaignItemCard", e.toString());
            return -1;
        }
    }

    private String ˎ(long j) {
        if (j != -1) {
            return DateUtils.formatDateTime(this.ʼॱ, j, 131092);
        }
        return "";
    }

    private void ˎ(float f) {
        this.ʿ.setAlpha(f);
        this.ˉ.setAlpha(f);
        this.ˋ.setAlpha(f);
    }

    private void ॱ(Context context, ImageView imageView) {
        if (imageView != null) {
            LayoutParams layoutParams = (LayoutParams) imageView.getLayoutParams();
            int ˋ = epv.ˋ(context, 96);
            layoutParams.setMarginStart((ˋ + azb.ˊ(context)) + context.getResources().getDimensionPixelSize(a.ʼ));
            layoutParams.setMarginEnd(azb.ˏ(context));
        }
    }
}
